package org.apache.flink.runtime.rest.messages.taskmanager;

import org.apache.flink.runtime.rest.messages.ResponseBody;
import org.apache.flink.util.Preconditions;

import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Collection;
import java.util.Objects;

/** Class containing a collection of {@link ResourceProviderInfo}. */
public class ResourceProvidersInfo implements ResponseBody {

    public static final String FIELD_NAME_TASK_MANAGERS = "taskmanagers";

    @JsonProperty(FIELD_NAME_TASK_MANAGERS)
    private final Collection<ResourceProviderInfo> resourceProviderInfos;

    @JsonCreator
    public ResourceProvidersInfo(
            @JsonProperty(FIELD_NAME_TASK_MANAGERS) Collection<ResourceProviderInfo> resourceProviderInfos) {
        this.resourceProviderInfos = Preconditions.checkNotNull(resourceProviderInfos);
    }

    public Collection<ResourceProviderInfo> getTaskManagerInfos() {
        return resourceProviderInfos;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        ResourceProvidersInfo that = (ResourceProvidersInfo) o;
        return Objects.equals(resourceProviderInfos, that.resourceProviderInfos);
    }

    @Override
    public int hashCode() {
        return Objects.hash(resourceProviderInfos);
    }
}
